package com.fzk.controller;

import com.fzk.core.FileStoreService;
import com.fzk.router.ApiHandler;
import com.fzk.router.AutoRegister;
import com.fzk.router.MyAutowire;
import com.fzk.router.MyRequestMapping;
import com.fzk.server.StaticResourcesHandler;

import java.nio.file.Path;

/**
 * 首页
 *
 * @author fzk
 * @datetime 2023-04-14 01:05:10
 */
@SuppressWarnings("unused")
@AutoRegister
public class IndexController {
    @MyAutowire(key = "fileService")
    private FileStoreService fileService;


    @MyRequestMapping(path = {"/favicon.ico", "/fs/favicon.ico"}, method = {"GET", "POST"})
    final ApiHandler favicon = (ctx, request, params) -> {
        Path path = Path.of("statics/images/favicon.ico");
        StaticResourcesHandler.serve(ctx, request, path);
    };

    @MyRequestMapping(path = {indexPageUri, indexPageUri + "/", indexPageUri + "/index.html"}, method = {"GET", "POST"})
    final ApiHandler index_ = (ctx, request, params) -> {
        Path path = Path.of("statics/html/index.html");
        StaticResourcesHandler.serve(ctx, request, path);
    };

    @MyRequestMapping(path = {"/fs/login", loginPageUri}, method = {"GET", "POST"})
    final ApiHandler loginPage = (ctx, request, params) -> {
        Path path = Path.of("statics/html/login.html");
        StaticResourcesHandler.serve(ctx, request, path);
    };

    public static final String rootPageUri = "/fs";// 根目录页
    public static final String indexPageUri = rootPageUri;// 首页
    public static final String loginPageUri = "/fs/login.html";// 登录页
}
